/*******************************************************************************
 * @project: ServletTest
 * @package: com.burns.servlet
 * @file: HelloWorld.java
 * @author: Administrator
 * @created: 2017-5-16
 * @purpose:
 * 
 * @version: 1.0
 * 
 * Revision History at the end of file.
 * 
 * Copyright 2017 AcconSys All rights reserved.
 ******************************************************************************/

package com.burns.servlet;

//导入必需的 java 库
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//扩展 HttpServlet 类
public class GetAccessToken extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void init() throws ServletException {
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
		// String code = (String) request.getAttribute("code");
		String access_token = request.getParameter("access_token");
		String expires_in = request.getParameter("expires_in");
		String username = request.getParameter("username");

		String url = "http://api.csdn.net/blog/getinfo?access_token"
				+ access_token;

		// 设置响应内容类型
		response.setHeader("content-type","text/html;charset=UTF-8");

		// 实际的逻辑是在这里
		PrintWriter out = response.getWriter();

		out.println("<h1>" + access_token + "</h1>");
		out.println("<h1>" + expires_in + "</h1>");
		out.println("<h1>" + username + "</h1>");
		out.println("<a href='" + url + "'>get_user_info</a>");
	}

	public void destroy() {
		// 什么也不做
	}
}

/*******************************************************************************
 * <B>Revision History</B><BR>
 * [type 'revision' and press Alt + / to insert revision block]<BR>
 * 
 * 
 * 
 * Copyright 2017 AcconSys All rights reserved.
 ******************************************************************************/
